package org.ipower.platform.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 日期格式。
 * */
public class DateFormat {
        /**
         * 获取yyyyMMddHHmmssSSS格式数据。
         * @return yyyyMMddHHmmssSSS格式数据。
         * */
        public static String getFormatDate() {
                String simple = "yyyyMMddHHmmssSSS";
                SimpleDateFormat sdf = new SimpleDateFormat(simple);
                Date currentDate = new Date();
                return sdf.format(currentDate);
        }
        /**
         * 
         * */
        public static java.sql.Date formatYMD(Object time) {
                Date r = null;
                try {
                        r = java.text.DateFormat.getDateInstance().parse(time.toString());
                } catch (Exception e) {
                }
                // SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
                if (null != r) {
                        // String str = formatter.format(r);
                        // Long l = Long.parseLong(str);
                        Date date = new Date(r.getTime());
                        java.sql.Date d = new java.sql.Date(date.getTime());
                        return d;
                }
                return null;
        }
        public static java.sql.Date format(Object val) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

                try {
                        java.util.Date d = java.text.DateFormat.getDateInstance().parse(
                                        val.toString());
                        String oldDate = sdf.format(d);
                        java.sql.Date date = new java.sql.Date(sdf.parse(oldDate).getTime());
                        return date;
                } catch (ParseException e) {
                        e.printStackTrace();
                }
                return null;
        }

        public static String getFormatDate(String date) {
                String simple = "yyyy-MM-dd";
                SimpleDateFormat sdf = new SimpleDateFormat(simple);
                return sdf.format(date);
        }

        public static String getFormatDate(Object date) {
                String simple = "yyyy-MM-dd";
                SimpleDateFormat sdf = new SimpleDateFormat(simple);
                return sdf.format(date);
        }

        public static java.sql.Date getSqlDate() {
                java.sql.Date date = new java.sql.Date(System.currentTimeMillis());
                return date;
        }
}